package day12_thread_code.com.itheima.d4_thread_synchornized_code;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Account {
    private String cardId;
    private double money;

    public void drawMoney(double drawMoney){
        String name = Thread.currentThread().getName();
        synchronized (this){
            if (this.money >= drawMoney){
                System.out.println(name + "取钱成功，取钱：" + drawMoney);
                this.money -= drawMoney;

                System.out.println(name + "取钱成功，余额：" + this.money);
            }else {
                System.out.println(name + "取钱失败，余额不足！");
            }

        }
    }
}
